<?php

namespace catchAdmin\system\controller;

use catcher\base\CatchController;
use catcher\base\CatchRequest;
use catcher\CatchResponse;
use app\common\model\PathTemplate as PathModel;

class PathTemplatenode extends CatchController
{
    protected $pathTemplate;

    public function __construct(PathModel $pathTemplate)
    {
        $this->pathTemplate = $pathTemplate;
    }

    /**
     * 列表
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index(): \think\response\Json
    {
        return CatchResponse::paginate($this->pathTemplate->getLists());
    }

    /**
     * 保存
     *
     * @time 2020年01月09日
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function save(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();
        return CatchResponse::success($this->pathTemplate->addData($req));
    }

    /**
     * 更新
     *
     * @time 2020年01月09日
     * @param $id
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function update($id, CatchRequest $request): \think\response\Json
    {
        return CatchResponse::success($this->pathTemplate->saveData($id, $request->param()));
    }

    /**
     * 删除
     *
     * @time 2020年01月09日
     * @param $id
     * @return \think\response\Json
     */
    public function delete($id): \think\response\Json
    {
        return CatchResponse::success($this->pathTemplate->destroy($id));
    }

    /**
     * 获取病种
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function getPathTemplateNode(CatchRequest $request): \think\response\Json
    {
        $ret = $this->pathTemplate->getConditionData([], 'name,value');
        return CatchResponse::success($ret);
    }
}